load(
    "@gz//bazel/skylark:build_defs.bzl",
    "GZ_FEATURES",
    "GZ_ROOT",
    "GZ_VISIBILITY",
    "gz_export_header",
    "gz_include_header",
)
load(
    "@gz//bazel/lint:lint.bzl",
    "add_lint_tests",
)

package(
    default_applicable_licenses = [GZ_ROOT + "common:license"],
    features = GZ_FEATURES,
)

public_headers_no_gen = glob([
    "include/gz/common/*.hh",
    "include/gz/common/**/*.hh",
])

sources = glob(
    ["src/*.cc"],
    exclude = ["src/*_TEST.cc"],
)

test_sources = glob(["src/*_TEST.cc"])

gz_export_header(
    name = "include/gz/common/events/Export.hh",
    export_base = "GZ_COMMON_EVENTS",
    lib_name = "gz-common-events",
    visibility = ["//visibility:private"],
)

gz_include_header(
    name = "events_hh_genrule",
    out = "include/gz/common/events.hh",
    hdrs = public_headers_no_gen + [
        "include/gz/common/events/Export.hh",
    ],
)

public_headers = public_headers_no_gen + [
    "include/gz/common/events/Export.hh",
    "include/gz/common/events.hh",
]

cc_library(
    name = "events",
    srcs = sources,
    hdrs = public_headers,
    includes = ["include"],
    visibility = GZ_VISIBILITY,
    deps = [
        GZ_ROOT + "common",
        GZ_ROOT + "utils",
    ],
)

[cc_test(
    name = src.replace("/", "_").replace(".cc", "").replace("src_", ""),
    srcs = [src],
    deps = [
        ":events",
        GZ_ROOT + "common/testing",
        "@gtest//:gtest_main",
    ],
) for src in test_sources]

add_lint_tests()
